package corejava3;

//可变参数，必须是最后一个参数 printf /scanf都是这么实现的
public class VariableArguments {
    public static void main(String[] args) {
        System.out.println(add());
        System.out.println(add(1));
        System.out.println(add(1, 2));
        System.out.println(add(1, 2, 3));
        System.out.println(add(1, 2, 3, 4));
    }

    public static int add(int... a) {
        int tot = 0;
        for (int i = 0; i < a.length; i++)
            tot += a[i];
        return tot;
    }
}
